<script src="../../../../../../protects/guangxifupin-front/src/containers/App/index.jsx"></script>
<template>
  <div class="padding-middle">
    <el-card :body-style="{padding:'0px'}">
      <div class="search">
        <div class="input" style="display: none">
          <el-input v-model="input" size="small" placeholder="请输入课程名称" style="width: 300px;height: 20px;margin-right: 15px"/>
          <span style="color: #fff;font-size: 14px">课程分类:</span>
          <el-select v-model="option1" placeholder="请选择课程分类" size="small" style="margin-right: 15px">
            <el-option
              v-for="item in options1"
              :key="item.value"
              :label="item.label"
              :value="item.value"/>
          </el-select>
          <span style="color: #fff;font-size: 14px">课程科目:</span>
          <el-select v-model="option2" placeholder="请选择课程科目" size="small">
            <el-option
              v-for="item in options2"
              :key="item.value"
              :label="item.label"
              :value="item.value"/>
          </el-select>
          <el-button style="margin-left: 15px" plain size="small" icon="el-icon-search">查询</el-button>
        </div>
        <div class="edit">
          <router-link to="/coursemanagement/uploadCourse/edit"><el-button type="success" size="small">上传课程</el-button></router-link>
        </div>
      </div>
      <el-row :gutter="20" >
        <el-col v-for="(item,index) in items" :key="index" :span="6" style="height: 370px">
          <div class="grid-content bg-purple">
            <div style="width: 376px">
              <div class="videoImgae" style="height: 100%">
                <a class="href" href="#" @click="playVideo(item.courseCover)">
                  <div :class="item.courseCover!==imgurl?'imgBg'+ ' cover':'imgBg'+ ''" >
                    <img :style="{display:item.courseCover!==imgurl? 'inline-block':'none'}" src="./imgaes/play.png">
                    <video v-if="item.url !='' && item.courseCover===imgurl" :id="item.courseCover" :src="'http://118.24.139.141:81/'+item.url" class="avatar" controls="controls">您的浏览器不支持视频播放</video>
                  </div>
                </a>
                <div class="btn">
                  <h4 style="margin: 0">{{ item.name }}</h4>
                  <router-link :to="'/coursemanagement/uploadCourse/edit/' +index+'/'+params.page"><el-button size="small" type="text">编辑</el-button></router-link>
                  <el-button type="danger" size="small" plain @click="deleteItem(item)">删除</el-button>
                </div>
              </div>
            </div>
          </div>
        </el-col>
      </el-row>
      <el-pagination
        :page-size="pageSize"
        :pager-count="pagerCount"
        :total="total"
        background
        layout="prev, pager, next"
        @current-change="sizeChange"/>
    </el-card>
  </div>
</template>

<script>
import axios from 'axios'
import { VERSION } from '@/constants/uri'
export default {
  data() {
    return {
      videoFlag:true,
      imgurl:'',
      id:'',
      bgurl:'url',
      page: 1,
      items: [],
      total:0,
      input:'100',
      option1:'',
      version:VERSION,
      options1:[],
      option2:[],
      options2:[],
      pageSize:10,
      pagerCount:11,
      params:{
        page:1,
        size:10,
        examType:'all',
        courseCategoryId:'all',
        courseSubjectId:'all'
      }
    }
  },
  mounted() {
    this.queryList()
  },
  methods: {
    queryList() {
      axios.post(`/getCourseInfoList` ,this.params).then(res => {
        if (res.success) {
          this.items = res.data
          this.total = res.total
        }
      })
    },
    playVideo(imgurl) {
      this.videoFlag=false
      this.imgurl=imgurl
    },
    sizeChange(page) {
      this.params.page=page
      this.queryList()
    },
    /*
     *   删除特定id行
     * */
    deleteItem(row) {
      if (!confirm('确定删除')) {
        return
      }
      axios.delete(`/delCourseInfo/${row.id}`).then(res => {
        if (res.success) {
          this.page = 1
          this.queryList()
        }
      })
    },
  }
}
</script>

<style lang="scss" scoped>
  .cover {
    width: 100px;
    height: 75px;
    box-shadow: 2px 2px 2px #eee;
  }
  .el-row {
    margin-bottom: 20px;
    &:last-child {
      margin-bottom: 0;
    }
  }
  .el-col {
    border-radius: 4px;
  }
  .bg-purple-dark {
    background: #fff;
  }
  .bg-purple {
    background: #fff;
    margin-top: 20px;
  }
  .bg-purple-light {
    background: #fff;
  }
  .grid-content {
    border-radius: 4px;
    min-height: 280px;
  }
  .row-bg {
    padding: 10px 0;
    background-color: #fff;
  }
  .videoImgae{
    text-align: center;
    position: relative;
    padding-bottom: 70px;
    .href{
      display: inline-block;
      width: 100%;
    }
    .imgBg{
     display: inline-block;
     height: 280px;
     width: 100%;

     background-size: 100% 100%;
      cursor: pointer;
      img{
        width: 60px;
        position: relative;
        top:124px;
        left: 10px;
        padding: 0;
        margin: 0;
      }
    }
    .btn{
      text-align: center;
      padding: 10px 0;
      position: absolute;
      top:300px;
      left: 140px;
    }
  }
  .search{
    background-color: #fff;
    height: 60px;
    display: flex;
    padding: 15px 10px;
    box-sizing: border-box;
    .input{
      flex: 8;
    }
    .edit{
      flex: 2;
      text-align: right;
      padding-right: 10px;
    }
  }
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 376px;
    height:208px;
    display: block;
  }
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 376px;
    height:208px;
    display: block;
  }
  .cover{
    background: url("./imgaes/cover.jpg");
  }
</style>
